import api from '../index';
import type { ResponseData, pageParam, RequestFromType, ResponseRowsRes } from '../type';
import type { GoodsItem, GoodsDetail, PreviewOneGoodsOrderParams, PurchaseGoodsParams, PurchaseGoodsPayData, OrderItem, OrderInfo } from '.';
// 我的商品列表
export const getYuncangGoodsList = (data: pageParam & RequestGoodsListParams) =>
	api.get<ResponseData<GoodsItem[], true>>('customer/api/repertory', {
		data
	});
// 商品详情
export const getYuncangGoodsDetail = (id: string) => api.get<ResponseData<GoodsDetail>>(`customer/api/repertory/detail/${id}`);
export const postYuncangPreviewOneGoodsOrder = (data: PreviewOneGoodsOrderParams) =>
	api.post<ResponseData<PreviewOrderData>>('customer/api/repertory/buy/pre', {
		data
	});
// 订单支付
export const postYuncangPurchaseOneGoods = (
	data: PurchaseGoodsParams & {
		skuId: string;
		qty: string;
	}
) =>
	api.post<PurchaseGoodsPayData>('customer/api/repertory/buy', {
		data,
		custom: {
			getError: true,
			isLoading:true
		}
	});
// 订单列表
export const getYuncangOrderList = (data: OrderParams & pageParam) =>
	api.get<ResponseData<OrderItem[]>>('customer/api/repertory/order', {
		data,
		custom: {
			isLoading: true
		}
	});
// 订单详情
export const getYuncangOrderDetail = (id: string) => api.get<ResponseData<OrderInfo>>(`customer/api/repertory/order/detail/${id}`);
// 取消订单
export const postYuncangCancelOrder = (id: string) =>
	api.post(`customer/api/repertory/cancel/pay/${id}`, {
		custom: {
			isLoading: true
		}
	});
// 待付款订单付款
export const postYuncangOrderRepayments = (data: { payId: number; fromType: string; payword?: string }) =>
	api.post<ResponseData<PurchaseGoodsPayData>>('customer/api/repertory/re/pay', {
		data,
		custom: {
			isLoading: true
		}
	});

// 销量数据
export const getStockSoldInfo = () => api.get('customer/api/repertory/sell/record/sales/volume');
// 销售的明细列表
export const getStockSoldList = (data) =>
	api.get('customer/api/repertory/sell/record/list', {
		data
	});
// 我的库存
export const getStockGoodsList = (data) =>
	api.get('customer/api/repertory/customer/list', {
		data
	});

/**
 * 库存明细
 * /customer/api/repertory/order/details
 */
export const getStockOrderDetailApi = (data) =>
	api.get('customer/api/repertory/order/details', {
		data
	});

export const pickupOrderDetailApi = (id:string) => api.get('product/customer/detail',{
		data: { id }
	});

export const pickupGoodsStockApi = (commodityId:string) => api.get('customer/api/repertory/order/maxStock',{
		data: { commodityId }
	})
/**
 * 
 * /customer/api/repertory/order/delivery
 * receivedId-收货地址ID
commodityId-商品ID
qty-提货数量
payword-支付密码
 */
export const pickupConfirmApi = (data) => {
	return api.post('customer/api/repertory/order/delivery',{
		data,
		header: {
			'Content-Type': 'application/json;'
		}
	});
};

/**
 * 提货详情
 * /customer/api/repertory/order/delivery/detail/{paycode}
 */
export const pickupOrderDeliveryDetail = (paycode) => api.get(`customer/api/repertory/order/delivery/detail/${paycode}`)

/**
 * 提货订单预览
 * /customer/api/repertory/order/pre
 */
export const pickupOrderPreApi = (data) => api.post('customer/api/repertory/order/pre',{
		data,
		header: {
			'Content-Type': 'application/json;'
		}
	});
